package de.joergviola.mobj.shared;

import java.io.Serializable;
import java.util.ArrayList;

public class Query implements Serializable {

	private static final long serialVersionUID = 3208877728406111788L;

	public static final String EQUAL = "=";

	ArrayList<Filter> filters = new ArrayList<Filter>();

	/**
	 * Add a string-value filter - find only objects, whose string-valued field
	 * has the value given. Multiple filters are ANDed.
	 * 
	 * @param field
	 *            Name of the field to query
	 * @param value
	 *            The value fields of found objects must have
	 */
	public void add(String field, String operator, String value) {
		filters.add(new Filter(field, operator, value));
	}

	/**
	 * Add a long-value filter - find only objects, whose long-valued field has
	 * the value given. Multiple filters are ANDed.
	 * 
	 * @param field
	 *            Name of the field to query
	 * @param value
	 *            The value fields of found objects must have
	 */
	public void add(String field, String operator, Long value) {
		filters.add(new Filter(field, operator, value));
	}

	public Iterable<Filter> getFilter() {
		return filters;
	}

	@Override
	public String toString() {
		return filters.toString();
	}
}
